home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performSubdAutoProj.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  12.4 KB  |  447 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  4 April 1997
  22. //
  23. //  Procedure Name:
  24. //      performSubdAutoProj
  25. //
  26. //  Description:
  27. //        
  28. //         
  29. //  Input Arguments:
  30. //        $option : Whether to set the options to default values.
  31. //  Return Value:
  32. //        command string iff $option==2
  33. //
  34.  
  35. //
  36. // Initialize optionVars for subdAutoProj:
  37. // Color, Texture, Vertex
  38. // 
  39. proc setOptionVars (
  40.     string        $prefix, 
  41.     int            $forceFactorySettings,
  42.     string        $vars[]
  43. )
  44. {
  45.     string $varName;
  46.  
  47.     // Must match $vars
  48.     int    $intValues[]= { 3, 1, 1, 2, 0 };
  49.  
  50.     for ( $i = size($vars) ; $i-- ; )
  51.     {
  52.         $varName = ($prefix + $vars[$i]);
  53.         if ($forceFactorySettings || !`optionVar -exists $varName`)
  54.             optionVar -intValue $varName $intValues[$i];
  55.     }
  56.  
  57.     $varName = ($prefix + "eg");
  58.     if ($forceFactorySettings || !`optionVar -exists $varName`)
  59.         optionVar -floatValue $varName .2;
  60.  
  61. /*
  62.     // Also add the map name
  63.     $varName = ($prefix + "uvSetName");
  64.     if ($forceFactorySettings || !`optionVar -exists $varName`)
  65.         optionVar -stringValue $varName "uvSet1";
  66. */
  67. }
  68.  
  69. global proc performSubdAutoProjSetup (string $parent, int $forceFactorySettings)
  70. {
  71.     string $prefix = "subdAutoProj";
  72.     // string $intVars[] ={"p", "o", "sc", "l", "cm"};
  73.     string $intVars[] ={"p", "o", "sc", "l"};
  74.     string $varName;
  75.     float  $presets[] = {.1, .2, .4, .8, 1.6, 3.2};
  76.     int    $i;
  77.  
  78.     setOptionVars($prefix, $forceFactorySettings, $intVars);
  79.     setParent $parent;
  80.     
  81.     $varName = ($prefix + $intVars[0]);
  82.     optionMenuGrp -e -sl `optionVar -query $varName` $varName;
  83.  
  84.     $varName = ($prefix + $intVars[1]);
  85.     radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName;
  86.  
  87.     $varName = ($prefix + $intVars[2]);
  88.     radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName;
  89.  
  90.     $varName = ($prefix + $intVars[3]);
  91.     radioButtonGrp -e -sl `optionVar -query $varName` $varName;
  92.  
  93.     $varName = ($prefix + "eg");
  94.     float $fval = `optionVar -q $varName`;
  95.     floatSliderGrp -e -v $fval $varName;
  96.  
  97.     // See if the value corresponds to one of the presets.
  98.     $varName = ($prefix + "egPresets");
  99.     optionMenuGrp -e -sl 1 $varName;
  100.     for ($i = size($presets) ; $i-- ; )
  101.     {
  102.         if ($fval == $presets[$i])
  103.         {
  104.             optionMenuGrp -e -sl ($i+2) $varName;
  105.             break;
  106.         }
  107.     }
  108.  
  109. /*
  110.     $varName = ($prefix + $intVars[4]);
  111.     int $val = `optionVar -query $varName`;
  112.     checkBoxGrp -edit -value1 $val $varName;
  113.     $varName = ($prefix + "uvSetName");
  114.     textFieldGrp -edit -en $val -tx `optionVar -q $varName` $varName; 
  115. */
  116. }
  117.  
  118. global proc performSubdAutoProjCallback (string $parent, int $doIt)
  119. {
  120.     string $prefix = "subdAutoProj";
  121.     string $intVars[] ={"p", "o", "sc", "l", "cm"};
  122.     string $varName;
  123.  
  124.     setParent $parent;
  125.     
  126.     $varName = ($prefix + $intVars[0]);
  127.     optionVar -intValue $varName `optionMenuGrp -q -sl $varName`;
  128.     
  129.     $varName = ($prefix + $intVars[1]);
  130.     optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1);
  131.     
  132.     $varName = ($prefix + $intVars[2]);
  133.     optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1);
  134.     
  135.     $varName = ($prefix + $intVars[3]);
  136.     optionVar -intValue $varName `radioButtonGrp -q -sl $varName`;
  137.     
  138. /*
  139.     $varName = ($prefix + $intVars[4]);
  140.     optionVar -intValue $varName `checkBoxGrp -query -value1 $varName`;
  141.  
  142.     $varName = ($prefix + "uvSetName");
  143.     optionVar -stringValue $varName `textFieldGrp -query -tx $varName`; 
  144. */
  145.  
  146.     $varName = ($prefix + "eg");
  147.     optionVar -floatValue $varName `floatSliderGrp -q -v $varName`;
  148.  
  149.     if ($doIt) 
  150.     {
  151.         performSubdAutoProj 0;
  152.         addToRecentCommandQueue "performSubdAutoProj 0" "SubdAutoProj";
  153.     }
  154. }
  155.  
  156. global proc subdAutoSpacingPresets()
  157. {
  158.     int $item = `optionMenuGrp -q -sl "subdAutoProjegPresets"`-2;
  159.     float  $presets[] = {.1, .2, .4, .8, 1.6, 3.2};
  160.  
  161.     if ($item>=0 && $item<6)
  162.         floatSliderGrp -e -v $presets[$item] "subdAutoProjeg";
  163. }
  164.  
  165. proc subdAutoProjOptions (string $prefix, string $intVars[])
  166. {
  167.     string $commandName = "performSubdAutoProj";
  168.     string $callback = ($commandName + "Callback");
  169.     string $setup = ($commandName + "Setup");
  170.     string $varName;
  171.  
  172.     string $layout = getOptionBox();
  173.     setParent $layout;
  174.     setUITemplate -pushTemplate DefaultTemplate;
  175.     waitCursor -state 1;
  176.     
  177.     string $parent = `columnLayout -adjustableColumn 1`;
  178.  
  179.     $varName = ($prefix + $intVars[0]);
  180.  
  181.     optionMenuGrp -l "Planes" $varName;
  182.     menuItem -l "4";
  183.     menuItem -l "5";
  184.     menuItem -l "6";
  185.     menuItem -l "8";
  186.     menuItem -l "12";
  187.     setParent -m ..;
  188.  
  189.     $varName = ($prefix + $intVars[1]);
  190.     radioButtonGrp -l "Optimize" -nrb 2
  191.         -l1 "Less Distortion" 
  192.         -l2 "Fewer Pieces" $varName;
  193.  
  194.     separator;
  195.  
  196.     $varName = ($prefix + $intVars[3]);
  197.     $gapName = ($prefix + "eg");
  198.     $menuName = ($prefix + "egPresets");
  199.     string $grayCmd = 
  200.         "{ int $tmp = `radioButtonGrp -q -sl "+$varName + "` == 2;" +
  201.         "  floatSliderGrp -e -en $tmp "+$gapName+";" +
  202.         "  optionMenuGrp -e -en $tmp "+$menuName+";}";
  203.     radioButtonGrp -l "Layout" -nrb 2 -cc $grayCmd
  204.         -l1 "Along U" 
  205.         -l2 "Into Square" $varName;
  206.  
  207.     $varName = ($prefix + $intVars[2]);
  208.     radioButtonGrp -l "Scale" -nrb 3
  209.         -l1 "None"
  210.         -l2 "Uniform"
  211.         -l3 "Stretch to Square" $varName;
  212.  
  213.     separator;
  214.  
  215.     optionMenuGrp -l "Spacing Presets" -cc subdAutoSpacingPresets $menuName;
  216.     menuItem -l " Custom";
  217.     menuItem -l "1024 Map";
  218.     menuItem -l " 512 Map";
  219.     menuItem -l " 256 Map";
  220.     menuItem -l " 128 Map";
  221.     menuItem -l "  64 Map";
  222.     menuItem -l "  32 Map";
  223.     setParent -m ..;
  224.  
  225.     string $cmd = ("optionMenuGrp -e -sl 1 " + $menuName);
  226.     floatSliderGrp -l "Percentage Space" -min 0 -max 5 -cc $cmd $gapName;
  227.  
  228. /*
  229.     separator;
  230.     separator;
  231.  
  232.     $varName = ($prefix + $intVars[4]);
  233.     $textName = ($prefix + "uvSetName");
  234.     string $grayCmd = 
  235.         "{ int $tmp = `checkBoxGrp -q -v1 "+$varName + "`;" +
  236.         "  textFieldGrp -e -en $tmp "+$textName+";}";
  237.     checkBoxGrp -label1 "Create New UV Set" -cc $grayCmd $varName;
  238.     textFieldGrp -label "UV Set Name: " $textName;
  239. */
  240.  
  241.     waitCursor -state 0;
  242.     setUITemplate -popTemplate;
  243.  
  244.     string $applyBtn = getOptionBoxApplyBtn();
  245.     button -edit -label "Project"
  246.            -command ($callback + " " + $parent + " " + 1) $applyBtn;
  247.     string $saveBtn = getOptionBoxSaveBtn();
  248.     button -edit 
  249.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  250.         $saveBtn;
  251.     string $resetBtn = getOptionBoxResetBtn();
  252.     button -edit 
  253.         -command ($setup + " " + $parent + " " + 1) $resetBtn;
  254.  
  255.     setOptionBoxTitle("Subdiv Automatic Mapping Options");
  256.  
  257.     setOptionBoxHelpTag( "SubdivAutomaticMapping" );
  258.  
  259.     eval (($setup + " " + $parent + " " + 0));
  260.  
  261.     showOptionBox();
  262. }
  263.  
  264. /*
  265. proc string createCurrentShader ()
  266. {
  267.     global string $subdTextureColorShader;
  268.     string $shader;
  269.     string $shaderType="lambert";
  270.     string $textureName="checker";
  271.     if (`optionVar -q subdCreateShaderWithMapping` == 0) 
  272.         return "";
  273.     string $shader=`evalEcho "sets -n texturedFacets -em -r true -nss true"`;
  274.     if ($shader != "") {
  275.         evalEcho ("partition -e -addSet renderPartition " + $shader);
  276.         string $shad[];
  277.         if ($subdTextureColorShader != "")
  278.             $shad=`ls -showType $subdTextureColorShader`;
  279.         if ($subdTextureColorShader == "" || size($shad) == 0) {
  280.             string $texture[]=`ls -showType defaultPolygonTexture`;
  281.             if (size($texture) == 0)
  282.                 $texture[0]=`evalEcho ("shadingNode -asTexture " 
  283.                         + $textureName + " -n defaultPolygonTexture")`;            
  284.             $subdTextureColorShader=`evalEcho ("shadingNode -asShader " 
  285.                         + $shaderType + " -n defaultPolygonShader")`;
  286.             evalEcho ("connectAttr " + $texture[0] + ".outColor " 
  287.                     + $subdTextureColorShader + ".color");
  288.             // creating a node selects it: we don't want that...
  289.             select -d $texture[0] $subdTextureColorShader;
  290.         }
  291.         $shad=`ls -showType $subdTextureColorShader`;
  292.         if ($subdTextureColorShader != "" && size($shad) != 0)
  293.             evalEcho ("connectAttr -f " + $subdTextureColorShader + ".outColor " 
  294.                                 + $shader + ".surfaceShader");
  295.         else warning "Could not create the default polygons shader";
  296.     } else warning "Could not create a new set to hold the faces.";
  297.     return $shader;
  298. }
  299. */
  300.  
  301. proc string getFacesToProject()
  302. {
  303.     // Returns a string representing the currently applicable
  304.     // selection items.  ie. if a subdiv surface is selected,
  305.     // then this returns a string containing its base faces.
  306.     // All base faces can be projected onto.
  307.     //
  308.     // If subd faces are already selected, then return nothing.
  309.     // If only subd objects are selected, then return string with all
  310.     // base faces.
  311.  
  312.     string $result = "";
  313.  
  314.     // There are already subd faces selected, just return
  315.     //
  316.     string $subdFaces[] = `filterExpand -sm 38`;
  317.     
  318.     // Find out if there are any subdivision surfaces selected
  319.     //
  320.     int $numSubdivs = 0;
  321.     string $selectedSubdivs[];
  322.     string $allSubds[] = `filterExpand -ex 1 -sm 68`;
  323.  
  324.     // If there are subd faces AND subd objects, then 
  325.     // display warning 
  326.     //
  327.     if( size($subdFaces) > 0 ) {
  328.         if( size($allSubds) > 0 ) {
  329.             warning(" Only the selected subdiv surface faces will be projected.  All selected subdiv surfaces will be ignored.");
  330.         }
  331.         return $result;
  332.     }
  333.  
  334.     for ( $obj in $allSubds ) {
  335.         $numSubdivs ++;
  336.         $selectedSubdivs[$numSubdivs-1] = $obj;
  337.     };
  338.  
  339.     if( $numSubdivs > 0 ) {
  340.         // create a string of subdiv faces from the selected subdivs
  341.         for ( $subd in $selectedSubdivs) {
  342.             string $tmp = "ls ";
  343.             $tmp += $subd;
  344.             $tmp += ".smf[\"*\"][\"*\"]" ;
  345.             $tmp += " ;";
  346.             string $allFaces[] = eval( $tmp );
  347.             for( $face in $allFaces ) {
  348.                 $result += " ";
  349.                 $result += $face;
  350.             }
  351.         }
  352.     }
  353.     return $result;
  354. }
  355.  
  356. global proc string performSubdAutoProj (int $option)
  357. {
  358.     string $prefix = "subdAutoProj";
  359.     // string $intVars[] ={"p", "o", "sc", "l", "cm"};
  360.     string $intVars[] ={"p", "o", "sc", "l"};
  361.     string $cmd="";
  362.  
  363.     switch ($option) 
  364.     {
  365.         case 0:
  366.  
  367.         // If nothing selected, then return 
  368.         // 
  369.         string $sel[] = `ls -sl`;
  370.         if( size($sel) == 0 ) {
  371.             warning(" Subdiv Surfaces Texture projection works only on subdiv surfaces or subdiv surface faces.");
  372.             return $cmd;
  373.         }
  374.  
  375.         string $varName;
  376.         int $ival;
  377.         setOptionVars($prefix, false, $intVars);
  378.         $cmd = "subdAutoProjection";
  379.         for ( $i = size($intVars) ; $i-- > 1; )
  380.         {
  381.             $varName = ($prefix + $intVars[$i]);
  382.             $ival = `optionVar -query $varName`;
  383.             $cmd = $cmd + " -" + $intVars[$i] + " " + $ival;
  384.         }
  385.  
  386.         $varName = ($prefix + $intVars[0]);
  387.         $ival = `optionVar -query $varName`;
  388.         int $numVal[] = {4, 5, 6, 8, 12};
  389.         $cmd = $cmd + " -" + $intVars[0] + " " + $numVal[$ival-1];
  390.  
  391. /*
  392.         // Code to get value of uvSetName if createNew UVSet is toggled on..
  393.         //
  394.         $varName = ($prefix + $intVars[4]);
  395.         $ival = `optionVar -query $varName`;
  396.         if ($ival)
  397.         {
  398.             $varName = ($prefix + "uvSetName");
  399.             string $sval = `optionVar -query $varName`;
  400.             if ($sval != "")
  401.                 $cmd = $cmd + " -uvSetName " + $sval;
  402.         }
  403. */
  404.  
  405.         $varName = ($prefix + "eg");
  406.         float $fval = `optionVar -query $varName`;
  407.         $cmd = $cmd + " -ps " + $fval;
  408.  
  409.         // Convert everything to subd faces, if necessary
  410.         //
  411.         string $selectionToProject = getFacesToProject();
  412.         $cmd += $selectionToProject;
  413.  
  414.         // polyPerformAction $cmd "f" 0;    
  415.         string $result[] = `eval $cmd`;    
  416.  
  417. /*
  418.         string $totalSel[] = `ls -sl`;
  419.         string $shader=`createCurrentShader`;
  420.         // Update shader's set.
  421.         if( $shader != "") {
  422.             $cmd=("sets -e -fe " + $shader);
  423.             int $i;
  424.             for($i=0; $i < size($totalSel); $i++)
  425.                 $cmd=($cmd + " " + $totalSel[$i]);
  426.             evalEcho $cmd;
  427.             evalEcho `select -r $totalSel`;
  428.         }
  429. */
  430.  
  431.         // Set selection
  432.  
  433.         break;
  434.  
  435.         case 1:
  436.             subdAutoProjOptions($prefix, $intVars);
  437.             break;
  438.         case 2:
  439.             $cmd="performSubdAutoProj 0";
  440.             break;
  441.     }
  442.  
  443.     // Return the name of the new projection node
  444.     //
  445.     return $result[0];
  446. }
  447.